<?php
//公用上传程序
//@author yuanjiang Date. 8.23.2013
define('IN_T',true);
require 'include/init.php';;

$act = Common::sfilter($_REQUEST['act']);

/* 未登录 */
if($company['id']<=0){
   echo $Json->encode(array('error'=>1,'message'=>'请先登录！'));
   exit;
}

/* 未上传文件 */
if(empty($_FILES))
{
   echo $Json->encode(array('error'=>1,'message'=>'非法请求！'));
   exit;
}

$old = getcwd();  //当前目录 
chdir(ROOT_PATH);  //切换到程序根目录
   
if(!empty($act)){
	$data['error'] = 1;
	list($picWidth, $picHeight) = getimagesize($_FILES['imgFile']['tmp_name']);   //图片高宽
	if($picWidth>1000){
		$data['message'] = '图片宽度不能超过1000px';
	}
	else{
		$dir_path = 'data/company/'.$act.'/'.date('Ym',Common::gmtime());
		Common::make_dir($dir_path);
		$file_path = $dir_path.'/'.Common::gmtime().'.png';
		
		if(move_uploaded_file($_FILES['imgFile']['tmp_name'],$file_path)){
			$data = array('error'=>0,'url'=>'/'.$file_path);
		}
		else{
			$data['message'] = '上传失败！';
		}
	}	
}

chdir($old);
echo $Json->encode($data);
exit;
?>